package com.sparrow.mongo;
import com.sparrow.common.util.PropertiesUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;

@Configuration
@ComponentScan("com.sparrow.mongo")
public class SparrowMongoAutoConfig {

    @Bean
    public MongoTemplate mongoTemplate() {
        // 只传 URI，包含数据库名，Spring 自动识别
        String uri = PropertiesUtil.getProperty("mongo.uri");
        return new MongoTemplate(new SimpleMongoClientDatabaseFactory(uri));
    }

}

